from src.common.readConfig import ReadConfig
import requests
from src.common import log
from src.common.dingding import send_group
from src.common.sign import signkey
import time

global host
ddxf_login_readconfig = ReadConfig ("prod")
host = ddxf_login_readconfig.get_url("ddxfhost")

def getVersion():
    url = ddxf_login_readconfig.get_url("ddxf_getVersion_url")
    version_url =ddxf_login_readconfig.get_url("ddxfHost_url")+url
    # 获取安卓版本号请求地址
    t = time.time()
    timestamp = str(round(t * 1000))
    signStr = timestamp+"GET/ddxf/app/upgrade?appId=com.fangdd.ddxf&platform=1"
    add_sign = signkey()
    req = add_sign.sign(str(signStr))
    print("签名", req)
    version_header = {"Device-Id": "866699037377522","Platform": "Android","City-Id": "-1","Sign": req,
	"Timestamp": timestamp,"Platform-Device": "OPPO","Content-Type": "application/json","Connection": "Keep-Alive",
	"Accept-Encoding": "gzip","User-Agent": "okhttp/3.11.0","APP_SECRET_ID": "HyaoSfSjRLKE9WNoBJfT8fsvgIQWTBRk",
	"APP_SECRET_KEY": "QR8oCEJWti0dqd19vz3rz33bac0QkQpxto","Host": "shopapi.fangdd.com "}
    res = requests.get(version_url, headers=version_header, verify=False)
    result = res.json()
    print(result)
    if result["code"] == 200:
        log.logger_info.info("获取版本号正常")
        # 获取当前版本号
        versionCode = result["data"]["versionName"]
        version = versionCode[1:]
        print(version)
        return version
    else:
        send_group("多多新房获取当前版本号异常:" + str(res) + "@13883217640", "13883217640")
        log.logger_error.error("多多新房获取当前版本号异常" + str(res))


if __name__ == '__main__':
    getVersion()
